package com.booking.springrestful.controller;

import com.booking.springrestful.domain.dto.PatternDto;
import com.booking.springrestful.domain.dto.PatternSaveDto;
import com.booking.springrestful.resp.PageResult;
import com.booking.springrestful.resp.ResponseResult;
import com.booking.springrestful.service.PatternLibraryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/pattern")
@Slf4j
public class PatternController {

    @Resource
    private PatternLibraryService patternService;

    /**
     * 分页查询纹样列表（支持筛选）
     */
    @PostMapping("/getPatternList")
    public ResponseResult<PageResult<PatternSaveDto>> getPatternList(@RequestBody PatternDto patternDto) {
        log.info("查询纹样列表，参数: {}", patternDto);
        PageResult<PatternSaveDto> result = patternService.getPatternList(patternDto);
        return ResponseResult.success(result);
    }

    /**
     * 批量删除纹样（支持单个或多个）
     */
    @PostMapping("/delPattern")
    public ResponseResult<String> delPattern(@RequestBody List<Long> ids) {
        log.info("删除纹样，ID列表: {}", ids);
        patternService.deletePatterns(ids);
        return ResponseResult.success("删除成功");
    }

    /**
     * 新增纹样
     */
    @PostMapping("/savePattern")
    public ResponseResult<String> savePattern(@RequestBody PatternSaveDto patternSaveDto) {
        log.info("新增纹样: {}", patternSaveDto);
        patternService.savePattern(patternSaveDto);
        return ResponseResult.success("新增成功");
    }

    /**
     * 根据 ID 查询纹样详情
     */
    @GetMapping("/getPatternById")
    public ResponseResult<PatternSaveDto> getPatternById(@RequestParam Long id) {
        log.info("查询纹样详情，ID: {}", id);
        PatternSaveDto dto = patternService.getPatternById(id);
        return ResponseResult.success(dto);
    }

    /**
     * 修改纹样
     */
    @PostMapping("/updatePattern")
    public ResponseResult<String> updatePattern(@RequestBody PatternSaveDto patternSaveDto) {
        log.info("修改纹样: {}", patternSaveDto);
        patternService.updatePattern(patternSaveDto);
        return ResponseResult.success("修改成功");
    }
}